package com.woniu.userservice.service.impl;

import com.woniu.userservice.dto.BiddingsDTO;
import com.woniu.userservice.entity.Biddings;
import com.woniu.userservice.dao.BiddingsDao;
import com.woniu.userservice.service.BiddingsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("biddingsService")
public class BiddingsServiceImpl implements BiddingsService {
    @Resource
    private BiddingsDao biddingsDao;

    @Override
    public Biddings queryById(Integer id) {
        return biddingsDao.queryById(id);
    }

    @Override
    public List<Biddings> queryAllByLimit(int offset, int limit) {
        return biddingsDao.queryAllByLimit(offset, limit);
    }
   
     @Override
    public List<Biddings> findAll() {
        return biddingsDao.findAll();
    }

    @Override
    public Biddings insert(Biddings biddings) {
        biddingsDao.insert(biddings);
        return biddings;
    }

    @Override
    public Biddings update(Biddings biddings) {
        biddingsDao.update(biddings);
        return queryById(biddings.getId());
    }

    @Override
    public boolean deleteById(Integer id) {
        return biddingsDao.deleteById(id) > 0;
    }

    @Override
    public List<BiddingsDTO> queryByGoodsid(Integer goodsid) {
        return biddingsDao.queryByGoodsid(goodsid);
    }

    @Override
    public Boolean deleteByUserId(Integer id, Integer userId) {
        if (id == null && userId ==null){
            return false;
        }
        else {
        biddingsDao.deleteByUserId(id,userId);
        return true;
        }
    }

    /**
     *
     * @param goodsName 商品名字
     * @param userId 用户id
     * @param price 商品价格
     * @param biddingTime 出价时间
     * @return
     */
    @Override
    public List<Biddings> findByMsg(String goodsName, Integer userId, Double price, Date biddingTime) {
        if (goodsName ==null&& userId ==null&&price ==null){
            return null;
        }else {
        return biddingsDao.findByMsg(goodsName,userId,price,biddingTime);
        }
    }
}